#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
const int MX = 1e5;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int f[N][20], dep[N];
void dfs(int u, int fu) {
  dep[u] = dep[fu] + 1;
  f[u][0] = fu;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
  }
}
void init() {
  dfs(1, 0);
  rep(j, 1, 16) rep(i, 1, n) f[i][j] = f[f[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 16, 0) if (d & (1 << j)) u = f[u][j];
  if (u == v) return u;
  per(j, 16, 0) if (f[u][j] != f[v][j]) u = f[u][j], v = f[v][j];
  return f[u][0];
}
struct Node {
  int mx;
  int id;
  int ch[2];
} tr[N << 6];
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
int newnode() {
  static int num = 0;
  return ++num;
}
void pushup(int p) {
  if (!p) return;
  tr[p].mx = max(tr[lc(p)].mx, tr[rc(p)].mx);
  if (tr[p].mx == tr[lc(p)].mx)
    tr[p].id = tr[lc(p)].id;
  else
    tr[p].id = tr[rc(p)].id;
}
void update(int x, int d, int& p, int l, int r) {
  if (!p) p = newnode();
  if (l == r) {
    tr[p].mx += d;
    tr[p].id = l;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, d, lc(p), l, mid);
  else
    update(x, d, rc(p), mid + 1, r);
  pushup(p);
}
void merge(int& p1, int p2, int l, int r) {
  if (!p1 || !p2) {
    p1 = p1 + p2;
    return;
  }
  if (l == r) {
    tr[p1].mx += tr[p2].mx;
    return;
  }
  int mid = (l + r) >> 1;
  merge(lc(p1), lc(p2), l, mid);
  merge(rc(p1), rc(p2), mid + 1, r);
  pushup(p1);
}
int root[N];
int ans[N];
void dfs_sum(int u, int fu) {
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs_sum(v, u);
    merge(root[u], root[v], 0, MX);
  }
  ans[u] = tr[root[u]].id;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  init();
  rep(i, 1, m) {
    int u, v, z;
    cin >> u >> v >> z;
    int x = lca(u, v);
    int y = f[x][0];
    update(z, 1, root[u], 0, MX);
    update(z, 1, root[v], 0, MX);
    update(z, -1, root[x], 0, MX);
    if (y) update(z, -1, root[y], 0, MX);
  }
  dfs_sum(1, 0);
  rep(i, 1, n) cout << ans[i] << endl;
  return 0;
}